package com.office.meetingManage.meetroom.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.office.meetingManage.meetroom.dao.ReservationmeetroomMapper;
import com.office.meetingManage.meetroom.pojo.OaReservationmeetroom;
import com.office.meetingManage.meetroom.pojo.otherPojo.MeetingParam;
import com.office.meetingManage.meetroom.service.ReservationmeetroomService;
import com.office.personalOffice.contacts.service.TbStaffService;
import com.office.util.PageModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会议服务接口实现类
 * @Auther: 许月
 * @Date: 2022/10/28/16:35
 */
@Service
public class ReservationmeetroomServiceImpl implements ReservationmeetroomService {
    @Autowired
    private ReservationmeetroomMapper reservationmeetroomMapper;
    @Autowired
    private TbStaffService tbStaffService;


    @Override
    public Boolean addMeeting(OaReservationmeetroom reservationmeetroom) {
        reservationmeetroom.setDeptId(tbStaffService.getById(reservationmeetroom.getReservationUserId()).getDeptId());
        Integer result = reservationmeetroomMapper.addMeeting(reservationmeetroom);
        if(result < 1){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public Boolean changeStatus(Integer mId, Integer status) {
        Integer result = reservationmeetroomMapper.changeStatus(mId,status);
        if(result < 0){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public PageModel<OaReservationmeetroom> getList(MeetingParam meetingParam, PageModel<OaReservationmeetroom> pageModel) {
        pageModel.setPageNum(pageModel.getPageNum() <= 0?1: pageModel.getPageNum());
        pageModel.setPageSize(pageModel.getPageSize() <= 0?3: pageModel.getPageSize());

        PageHelper.startPage(pageModel.getPageNum(),pageModel.getPageSize());
        List<OaReservationmeetroom> meetingList = reservationmeetroomMapper.queryList(meetingParam);
        System.out.println("获得的列表长度"+meetingList.size());
        PageInfo<OaReservationmeetroom> pageInfo = new PageInfo<>(meetingList);
        pageModel.setData(meetingList);
        pageModel.setTotalPage(pageInfo.getPages());
        pageModel.setTotalRows(pageInfo.getTotal());
        return pageModel;
    }


    /**
     * 取消会议
     * @param rid
     * @return
     */
    @Override
    public Boolean deleteMeeting(Integer rid) {
        Integer result = reservationmeetroomMapper.deleteByRid(rid);
        if(result < 0){
            return false;
        }else {
            return true;
        }
    }

    /**
     * 审批会议
     * @param reservationmeetroom
     * @return
     */
    @Override
    public Boolean approval(OaReservationmeetroom reservationmeetroom) {

        Integer result = reservationmeetroomMapper.approval(reservationmeetroom);
        if(result < 0){
            return false;
        }else {
            return true;
        }
    }
}
